<template>
  <div class="boxContent">
    <div class="appBox">
      <div class="searchList">
        <el-form :model="state.params"
                 ref="FormInstance "
                 class="boxFrom">
          <div class="searchBox">
            <template v-for="(item, index) in state.totalInputColumns"
                      :key="index">

              <el-form-item v-if="item.type == 'input'">
                <el-input v-model="state.params[item.key]"
                          clearable
                          :placeholder="item.label"></el-input>
              </el-form-item>
              <el-form-item v-if="item.type == 'select'">
                <el-select v-model="state.params[item.key]"
                           :placeholder="item.label"
                           clearable
                           v-if="item.key == 'type'">
                  <el-option label="我能提供人"
                             value="0" />
                  <el-option label="我能提供岗位"
                             value="1" />
                </el-select>

              </el-form-item>
              <el-form-item v-if="item.type == 'time'">
                <el-date-picker v-model="state.params[item.key]"
                                type="daterange"
                                value-format="YYYY-MM-DD"
                                start-placeholder="开始日期"
                                range-separator="至"
                                end-placeholder="结束日期"
                                :placeholder="item.label" />
              </el-form-item>
            </template>
          </div>

          <el-form-item class="btns">
            <el-button v-preventReClick
                       type="primary"
                       plain
                       @click="methods.handleAction('query')">搜索</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="tabaleBox">
        <el-table border
                  v-loading="state.loading"
                  :data="state.tableData"
                  style="width: 100%"
                  :header-cell-style="{ color: '#000' }">

          <el-table-column prop="updatedAt"
                           label="时间"
                           show-overflow-tooltip
                           align="center"
                           width="180">
          </el-table-column>
          <el-table-column prop="readCount"
                           width="160"
                           label="姓名"
                           show-overflow-tooltip
                           align="center">
            <template #default="scope">
              <span class="error"
                    v-if="scope.row.handlePriority > 0">{{ scope.row.cooperationName }}（重复反馈）</span>
              <span v-else>{{ scope.row.cooperationName }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="cooperationPhone"
                           width="120"
                           label="电话"
                           show-overflow-tooltip
                           align="center">
          </el-table-column>
          <el-table-column prop="cooperationProvinceName"
                           width="120"
                           label="省份"
                           show-overflow-tooltip
                           align="center">
          </el-table-column>
          <el-table-column prop="cooperationCityName"
                           width="120"
                           label="城市"
                           show-overflow-tooltip
                           align="center">
          </el-table-column>

          <el-table-column prop="cooperationType"
                           width="120"
                           label="合作类型"
                           show-overflow-tooltip
                           align="center">
            <template #default="scope">
              <span v-if="scope.row.cooperationType == 0">我能提供人</span>
              <span v-if="scope.row.cooperationType == 1">我能提供岗位</span>
              <span v-if="scope.row.cooperationType == 2">劳务/企业招聘合作</span>
              <span v-if="scope.row.cooperationType == 3">其他合作</span>
            </template>
          </el-table-column>
          <el-table-column prop="cooperationContent"
                           label="合作内容"
                           show-overflow-tooltip
                           align="left">
          </el-table-column>
          <el-table-column prop=""
                           label="操作"
                           align="center"
                           width="140">
            <template #default="scope">
              <div class="btnsDatil flex_c">
                <!-- 其它操作 -->
                <div @click="methods.handleAction('edit', scope.row)"
                     v-permission="1152">查看和备注</div>
                <!-- <div @click="methods.handleAction('delete', scope.row)"
                     class="ml14">删除</div> -->
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <el-pagination background
                       v-model:current-page="state.params.pageNum"
                       v-model:page-size="state.params.pageSize"
                       :page-sizes="[10, 20, 30, 50]"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="state.totalSize"
                       @size-change="methods.handleSizeChange"
                       @current-change="methods.handleCurrentChange">
        </el-pagination>
      </div>

      <el-dialog v-model="state.dialogVisible"
                 v-if="state.dialogVisible"
                 title="查看和备注"
                 width="50%"
                 center>
        <div>
          <div class="flex mb20"
               v-for="i in state.remakes"
               :key="i">
            <div>
              {{i.handlerName}}：
            </div>
            <div class="ml20 flex1">{{ i.commentContent }}</div>
            <div class="ml20 ">{{ i.updatedAt }}</div>
          </div>
          <el-input v-model="state.valueInput"
                    size="large"
                    clearable
                    type="textarea"
                    placeholder="添加联系结果">
          </el-input>
          <div class="tar mt20">
            <el-button v-preventReClick
                       @click="state.dialogVisible = false"> 取消</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('subAdd')"
                       type="primary"> 保存</el-button>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  onMounted,
  reactive,
  toRefs,
  defineComponent,
  getCurrentInstance,
  nextTick,
} from "vue";
import Editor from '@/components/Editor.vue'
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
const router = useRouter();
const app = getCurrentInstance()?.proxy;
const initState = () => {
  return {
    loading: false,
    dialogVisible: false,
    totalSize: 0,
    dialogVisibleData: {},
    tableData: [],
    remakes: [],
    params: {
      pageNum: 1,
      pageSize: 10,
    },
    totalInputColumns: [
      { key: "date", label: "选择时间", type: "time" },
      { key: "name", label: "姓名", type: "input" },
      { key: "phone", label: "手机号", type: "input" },
      { key: "type", label: "合作类型", type: "select" },
    ],
    valueInput: '',
    dialogData: '',
  };
};
const state = reactive(initState());
onMounted(() => {
  methods.getDataList();
});
const methods = {

  handleAction (type, data) {
    switch (type) {
      case "edit":
        state.dialogVisible = true
        methods.editData(data)
        state.dialogVisibleData = data
        break;
      case "add": //新增
        state.type = 'subAdd'
        state.valueInput = ''
        state.dialogVisible = true
        break;
      case "subAdd": //保存
        if (state.valueInput == '') {
          return ElMessage.error('请输入内容')
        }
        app.$post('sysbuscooperatecomment/add', {
          "cooperationId": state.dialogVisibleData.id,
          "commentContent": state.valueInput
        }).then(res => {
          if (res.code == 200) {
            ElMessage.success('添加成功')
            state.valueInput = ''
            methods.getDataList()
            state.dialogVisible = false
          }
        })
        break;
      case "delete": // 删除
        ElMessageBox.confirm("请确认是否删除该公告?", "删除公告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            app.$get("/sysNotice/deleteById?id=" + data.id).then((res) => {
              methods.getDataList();
              ElMessage({
                type: "success",
                message: "已删除",
              });
            });
          })
        break;

      case "query": //查询
        methods.getDataList();
        break;
      case "reset": // 重置
        state.params = initState().params;
        break;
    }
  },
  editData (data) {
    app.$get('sysbuscooperatecomment/query?id=' + data.id).then(res => {
      if (res.code == 200) {
        state.remakes = res.data
      }
    })
  },


  getDataList () {
    state.loading = true
    let data = JSON.parse(JSON.stringify(state.params))
    data.date = data.date ? data.date.join() : ""
    app.$get("/sysbuscooperate/query", data)
      .then((res) => {
        state.tableData = res.data.data;
        state.totalSize = res.data.total;
        state.loading = false;
      }).catch(() => {
        state.loading = false
      })
  },
  //分页变化
  handleSizeChange () {
    state.params.pageNum = 1;
    methods.getDataList();
  },
  //表格翻页
  handleCurrentChange () {
    methods.getDataList();
  },
};
</script>

<style lang="scss" scoped>
.appBox {
  background: #fff;
  border-radius: 5px;
  padding: 20px;
  height: calc(100% - 20px);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;

  .tabaleBox {
    overflow: hidden;
    flex: 1;
  }
  .btnsDatil {
    color: #0079fe;
    cursor: pointer;
  }
  .pagination {
    margin-top: 20px;
    height: 50px;
    display: flex;
    justify-content: flex-end;
  }
  ::v-deep(.el-dialog__body) {
    padding: 20px 30px !important;
  }
  .imgs {
    flex-wrap: wrap;
    .forbox {
      // width: 150px;
      height: 150px;
      margin: 10px 0 0 10px;
    }
    .imgBox {
      height: 100%;
      width: auto;
    }
    .videoBox {
      width: auto;
      height: 100%;
    }
  }
}
</style>
